# centos 7
FROM centos:7 as builder

# copy conf_file
ADD conf/* /usr/local/src/fdfs/

# run
RUN sed -e 's|^mirrorlist=|#mirrorlist=|g' \
         -e 's|^#baseurl=http://mirror.centos.org|baseurl=https://mirrors.tuna.tsinghua.edu.cn|g' \
         -i.bak \
         /etc/yum.repos.d/CentOS-*.repo \
  &&    yum makecache \
  &&    yum install git gcc gcc-c++ make automake autoconf libtool pcre pcre-devel zlib zlib-devel openssl-devel wget vim -y \
  &&    cd /usr/local/src  \
  &&    git clone https://gitee.com/fastdfs100/libfastcommon.git --depth 1        \
  &&    git clone https://gitee.com/fastdfs100/fastdfs.git --depth 1    \
  &&    git clone https://gitee.com/fastdfs100/fastdfs-nginx-module.git --depth 1   \
  &&    wget http://nginx.org/download/nginx-1.15.4.tar.gz    \
  &&    tar -zxvf nginx-1.15.4.tar.gz    \
  &&    mkdir /home/dfs   \
  &&    cd /usr/local/src/  \
  &&    cd libfastcommon/   \
  &&    ./make.sh && ./make.sh install  \
  &&    cd ../  \
  &&    cd fastdfs/   \
  &&    ./make.sh && ./make.sh install  \
  &&    cd ../  \
  &&    cd nginx-1.15.4/  \
  &&    ./configure --add-module=/usr/local/src/fastdfs-nginx-module/src/   \
  &&    make && make install  \
  &&    cd ../ \
  &&    rm -rf nginx-1.15.4.tar.gz \
  &&    mv /usr/bin/fdfs* . \
  &&    tar -cvf fastdfs.tar ./ 


FROM centos:7

COPY --from=builder /usr/local/src/fastdfs.tar /usr/local/src/

RUN cd /usr/local/src \
  && tar xvf fastdfs.tar \
  && mv /usr/local/src/fdfs /etc/ \
  && mv fdfs* /usr/bin/ \
#  && ls -al /etc/fdfs/
  && chmod +x /etc/fdfs/fastdfs.sh \
  && cp -avx /usr/local/src/libfastcommon/src/libfastcommon.so /usr/lib64/ \
  && ln -s /usr/lib64/libfastcommon.so /usr/lib/libfastcommon.so \
  && ln -s /usr/local/src/fastdfs/init.d/fdfs_trackerd /etc/init.d/fdfs_trackerd \
  && ln -s /usr/local/src/fastdfs/init.d/fdfs_storaged /etc/init.d/fdfs_storaged 

# export config
VOLUME /etc/fdfs

EXPOSE 22122 23000 8888
ENTRYPOINT ["/etc/fdfs/fastdfs.sh"]
